﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Entities
{
    public class InterviewResultData
    {
        public int TotalCount 
        { 
            get 
            {
                int tc = 0;
                foreach (var t in ResultData)
                {
                    tc += t.Value.Count();
                }
                return tc;
            } 
        }
        public int SourceInterviewID { get; set; }
        public Dictionary<int, Dictionary<string, int>> ResultData { get; private set; }

        public int this[int question_id, string answer]
        {
            get
            {
                if (this.ResultData.ContainsKey(question_id))
                {
                    if (this.ResultData[question_id].ContainsKey(answer))
                    {
                        return this.ResultData[question_id][answer];
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                    return 0;
            }
            set
            {
                if (value < 0)
                {
                    return;
                }
                if (this.ResultData.ContainsKey(question_id))
                {
                    if (this.ResultData[question_id].ContainsKey(answer))
                    {
                        this.ResultData[question_id][answer] = value;
                    }
                    else
                    {
                        this.ResultData[question_id].Add(answer, value);
                    }
                }
                else
                {
                    this.ResultData.Add(question_id, new Dictionary<string,int>());
                    this.ResultData[question_id][answer]=value;
                }
            }
        }

        public InterviewResultData(int id = -1)
        {
            this.ResultData = new Dictionary<int,Dictionary<string, int>>();
            this.SourceInterviewID = id;
        }

        public InterviewResultData(int id,Dictionary<int, Dictionary<string, int> > data)
        {
            if (data == null)
            {
                throw new ArgumentNullException();
            }
            if (data.Count == 0)
            {
                throw new ArgumentException();
            }
            this.SourceInterviewID = id;
            this.ResultData = data;
        }
    }
}
